<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp" %>
<%@include file="/common/javascript.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>QSO</title>
    <link  href="${ctx}/static/css/index.css" rel="stylesheet" type="text/css" /> 
    <link  href="${ctx}/static/ligerui/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" /> 
    
    <script src="${ctx }/static/ligerui/lib/jquery/jquery-1.5.2.min.js" type="text/javascript"></script>   
    <script src="${ctx}/static/ligerui/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script> 
    <script src="${ctx}/static/ligerui/lib/js/ligerui.expand.js" type="text/javascript"></script> 
    <link href="${ctx}/static/ligerui/lib/css/common.css" rel="stylesheet" type="text/css" />  
    <link href="${ctx}/static/ligerui/lib/css/index.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/css/instruction/css/main.css" rel="stylesheet" type="text/css" />
    
    <script src="${ctx}/static/ligerui/lib/js/LG.js" type="text/javascript"></script>
    <script src="${ctx}/static/js/common.js" type="text/javascript"></script>
    <script src="${ctx}/static/js/comet/comet.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    	var dialog;
        
        $(document).ready(function ()
        {
            $("#mainbody").ligerLayout({ height: '100%', heightDiff: -3});

            //预加载dialog的背景图片
            LG.prevDialogImage("${ctx}");

            $("#pageloading").hide();
            
            loadMembers();
            
            loadAttachment();
            
            OnConnect();
            
            //
            $("#messageInput").focus();
        });
        
        //连接虚机
		function OnConnect() {
			window.ViewerX.Disconnect();
			window.ViewerX.HostIP = $("#ip").val();
			window.ViewerX.Port = $("#port").val();
			window.ViewerX.Password=$("#pwd").val();
			window.ViewerX.RemoteInputEnabled="1";
			window.ViewerX.Connect();
		}
		
        //加载讨论组成员
        function loadMembers(){
        	$("#memberList").empty();
        	LG.ajax({
        		url:"${ctx}/qso/instruct/getMembers",
        		data:{groupId:$("#groupId").val()},
        		success:function(result){
        			if(result.success){
        				var items=result.items;
        				for ( var i = 0; i < items.length; i++) {
        					if(items[i].lineStatus == 1){
        						$("#memberList").append(
            							"<li id='li_"+items[i].userId+"' class='onLine'>" + items[i].userName+"</li>");
        					}else{
        						$("#memberList").append(
            							"<li id='li_"+items[i].userId+"' class='offLine'>" + items[i].userName+"</li>");
        					}
        					
        				}
        			}else{
        				alert("result error is:"+result.error+"\n result.items is:"+result.items);
        			}
        		},
        		error:function(xmlRequest,info,throwObj){
        			alert("xmlRequest is:"+xmlRequest+"\n info is:"+info+"\n throwObj is:"+throwObj);
        		}
        	});
        }
        
    	//群聊,发送消息
    	function send() {
    		var message = $("#messageInput").val();
    		if($.trim(message)==""){
    			LG.tip("请输入信息...");
    			return;
    		}
    		$.ajax({
    			type : "POST",
    			url : "${ctx}/qso/instruct/sendToGroup/",
    			dataType : "json",
    			data : {
    				groupId :$("#groupId").val(),
    				command :"message",
    				message : message
    			},
    			success : function(result) {
    			}
    		});
    		$("#messageInput").val("");
    	}
   

    	//接收服务器消息
    	function receive(result) {
    		if(result.command==comet_command_message){
    			$("#messageArea").append("<BR>\n<font color=blue>" + result.sender + " " + result.sendTime+ " 说: </font>" + result.text+"\n<BR>");
    	        var scrollTop = $("#messageArea")[0].scrollHeight;  
    		    $("#messageArea").scrollTop(scrollTop);
    		}else if(result.command==comet_command_login){//有用户登陆
    			var li=$("#li_"+result.sender);
    			li.removeClass().addClass("onLine");
    		}else if(result.command==comet_command_logout){//有用户登出
    			var li=$("#li_"+result.sender);
    			li.removeClass().addClass("offLine");
    		}else if(result.command==comet_command_notify){
    			alert("讨论组通知: "+result.text);
    		}else if(result.command==comet_command_updateUserList){//更新用户列表
    			loadMembers();
      		}else if(result.command==comet_command_updateAttachmentList){//更新附件列表
    			loadAttachment();
    		}else if(result.command==comet_command_toExit){
                $.ligerDialog.confirm('老师请你退出讨论组!',"toExitGStu", function (yes) {
                    if (yes){
                    	window.parent.closeTheDialog(6);
                    }
                });
    		}
    	}
    	
    	function closeDialog(){
    		dialog.close();
    	}
    	
    	//加在附件列表
    	function loadAttachment(){
        	$("#attachmentList").empty();
        	LG.ajax({
        		url:"${ctx}/qso/attachment/getAttachment",
        		data:{bId:$("#groupId").val(),bType:"qso_discussion_group"},
        		success:function(result){
        			if(result.success){
        				var items=result.items;
        				for(var i=0;i<items.length;i++){
        					$("#attachmentList").append("<li>" + items[i].originalName+ "<a href='${ctx}/qso/attachment/downLoad/"+items[i].id+"'>下载</a></li>");
        				}

        			}else{
        				alert("获取附件列表失败!");
        			}

        		}
        	});
    	}
    </script>
</head>
<body style="text-align:center; background:url('${ctx}/static/ligerui/lib/images/qso/bg-1477x768.jpg'); overflow:hidden;">
 	<input type="hidden" id="groupId" name="groupId" value="${groupId }"/>	
	<input type="hidden" id="ip" value="${vu.vm.ip }"/>
	<input type="hidden" id="port" value="${vu.vm.port}"/>
	<input type="hidden" id="pwd" value="${vu.vm.pwd}"/>
			
    <div id="pageloading" style="display:block;"></div>
     <div id="mainbody" class="l-mainbody" style="width:99.2%; margin:0 auto; margin-top:3px;" >
        <div position="center" id="framecenter" style="background:#FFFFFF;"> 
            <div style="width:45%;height:85%; float:left; padding:5px;overflow-x:auto;overflow-y:auto"> 
				<p>
			<OBJECT classid= "CLSID:5220CB21-C88D-11CF-B347-00AA00A28331" VIEWASTEXT>
				<PARAM NAME="LPKPath" VALUE="${ctx}/static/vnc/scvncctrl.lpk" />
			</OBJECT>

					<OBJECT id="ViewerX" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid"
						height="650px" width="100%" classid="CLSID:62FA83F7-20EC-4D62-AC86-BAB705EE1CCD" VIEWASTEXT codebase="${ctx}/static/vnc/scvncctrl.cab#version=3,5,4,0">
						<!-- <param name="LPKPath" value="${ctx}/static/vnc/scvncctrl.lpk" /> -->
						<PARAM NAME="HostIP" VALUE="">
						<PARAM NAME="Port" VALUE="">
						<PARAM NAME="Password" VALUE="">
						<PARAM NAME="CustomCompression" VALUE="0">
						<PARAM NAME="CustomCompressionLevel" VALUE="6">
						<PARAM NAME="JPEGCompression" VALUE="1">
						<PARAM NAME="JPEGCompressionLevel" VALUE="6">
						<PARAM NAME="CopyRect" VALUE="1">
						<PARAM NAME="EmulateThreeButton" VALUE="1">
						<PARAM NAME="SwapMouseButtons" VALUE="1">
						<PARAM NAME="Encoding" VALUE="7">
						<PARAM NAME="ViewOnly" VALUE="1">
						<PARAM NAME="RestrictPixel" VALUE="0">
						<PARAM NAME="ScaleNum" VALUE="1">
						<PARAM NAME="ScaleDen" VALUE="1">
						<PARAM NAME="ScaleEnable" VALUE="0">
						<PARAM NAME="FullScreen" VALUE="0">
						<PARAM NAME="LocalCursor" VALUE="0">
						<PARAM NAME="MessageBoxes" VALUE="1">
						<PARAM NAME="DisableClipboard" VALUE="1">
						<PARAM NAME="ThumbnailMode" VALUE="0">
						<PARAM NAME="LoginType" VALUE="0">
						<PARAM NAME="MsUser" VALUE="">
						<PARAM NAME="MsDomain" VALUE="">
						<PARAM NAME="MsPassword" VALUE="">
						<PARAM NAME="ProxyIP" VALUE="">
						<PARAM NAME="ProxyPort" VALUE="-1">
						<PARAM NAME="ProxyUser" VALUE="">
						<PARAM NAME="ProxyPassword" VALUE="">
						<PARAM NAME="ProxyType" VALUE="0">
						<PARAM NAME="ConnectionBar" VALUE="1">
						<PARAM NAME="StretchMode" VALUE="0">
						
						
						<param name="RemoteInputEnabled" value="1">
						
						<param name="Chat" value="1">

					</OBJECT>
				</p>
               <%--  <img src="${ctx}/static/css/instruction/img/tempWindow.png" style="width:100%;height:100%;" /> --%>
            </div>
            <div style="width:54%; height:85%; float:right;">
            	<div class="inst-winchat">
            		<textarea id="messageArea" style="width:100%;height:100%;background:#CFE1E6;text-align:left;">
            		</textarea>
            	</div>
            	<div class="inst-stu-list">
            		<ul style="margin-left:10px; margin-top:10px;" id="memberList">
            		</ul>
            	</div>
            	<div style="clear:both;"></div>
            	<div class="inst-chat-input">
            		<textarea id="messageInput" style="width:100%;height:70%;color:#555;"></textarea>
            		<div class="inst-chat-send">
            			<div style="width:60px" class="button button2"  onclick="send()">
						<div class="button-l"> </div>
						<div class="button-r"> </div> 
						<div class="button-icon"><img src="${ctx}/static/css/instruction/img/sending.png" style="vertical-align:middle;" /> </div>
						<span>发送</span>
						</div>
            		</div>
            	</div>
            	<div class="inst-attachment">
            		<div style="background:#7E9CA3;">附件列表</div>
            		<ul class="inst-attachment-list" id="attachmentList">
            		</ul>
            	</div>
            </div>
            <div style="clear:both;"></div>
            <div style="width:100%; margin-left:10px;"><img src="${ctx}/static/css/instruction/img/avatar.png" />${vu.user.userNameC }的桌面</div>          
        </div> 
    </div>
    <div class="l-hidden"></div>
</body>
</html>